/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package chatNI;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 * @author gaye
 */
public class TCPCom extends Thread {

    private ServerSocket server;
    private File fichier;

    public TCPCom(int port, String chemin) throws IOException {
        this.server = new ServerSocket(port);
        this.fichier = new File(chemin);
        
    }

    @Override
    public void run() {
        Socket soc;

        try {
            soc = server.accept();

            int count;
            byte[] buffer = new byte[1024];

            OutputStream out = soc.getOutputStream();
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(fichier));
            while ((count = in.read(buffer)) > 0) {
                out.write(buffer, 0, count);
                out.flush();
            }
            soc.close();
        } catch (Exception e) {
            System.err.println(e);
        }
    }
}
